import time 

from vnpy.event.engine import EventEngine
from vnpy.event.engine import Event 
from vnpy.trader.engine import MainEngine

# 设置两个引擎实例
event_engine = EventEngine()
main_engine = MainEngine(event_engine)
print("The two engines start!")
# time.sleep(10)

# 自制一个Event用于测试
# 具体来讲，就是创建Event及相关Handler
# 将Handler注册，并在希望测试Event的时候，将Event推送到队列中
# 为了测试使用，这里会对某一个Event注册两个Handler
# Handler格式：handler(event)

# 创建我的Event
test_event = Event(type="testEvent", data="Here is the test event!")

# 创建第一个event的Handler
def process_event_func_1(event: Event):
    print("This is the first event")
    print(event.data)

# 创建第二个event的Handler
def process_event_func_2(event: Event):
    print("This is the second event")
    print(event.data)

# 将handler注册到event_engine中
event_engine.register("testEvent", process_event_func_1)
event_engine.register("testEvent", process_event_func_2)

# 将Event推送到队列中
event_engine.put(test_event)

# 等待10s，之后再次推送一遍
time.sleep(10)
event_engine.put(test_event)


main_engine.close()
print("The engine is stopped")